<?php
/**
 * Created by PhpStorm.
 * User: 清行
 * Date: 2019/3/21
 * Time: 9:27
 */

namespace xiaokang;
use Illuminate\Database\Capsule\Manager as Capsule;

class Model
{
    public function __construct()
    {
        $driver = Config::get('default','database');
        $connections = Config::get('connections','database');
        $capsule = new Capsule;
        // 创建链接
        $capsule->addConnection(array(
            'driver'    => $driver,
            'host'      => $connections[$driver]['host'],
            'port'      => $connections[$driver]['port'],
            'database'  => $connections[$driver]['database'],
            'username'  => $connections[$driver]['username'],
            'password'  => $connections[$driver]['password'],
            'charset'   => $connections[$driver]['charset'],
            'collation' => $connections[$driver]['collation'],
            'prefix'    => '',
        ));
        // 设置全局静态可访问DB
        $capsule->setAsGlobal();
        // 启动Eloquent （如果只使用查询构造器，这个可以注释）
        $capsule->bootEloquent();
    }
}